package com.pirestupppai.ui.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ToggleButton;

import com.pirestupppai.R;
import com.pirestupppai.base.BaseActivity;
import com.pirestupppai.common.Constant;
import com.pirestupppai.utils.SharedPreferenceUtil;

import butterknife.BindView;

/**
 * 消息提醒设置页
 *
 * @author: xiaoluo
 * @date: 2017-04-27 16:47
 */
public class NotificationActivity extends BaseActivity{

    @BindView(R.id.comment_tb)
    ToggleButton commentTb;
    @BindView(R.id.feed_comment_tb)
    ToggleButton feedCommentTb;
    @BindView(R.id.follow_tb)
    ToggleButton followTb;
    @BindView(R.id.like_tb)
    ToggleButton likeTb;
    @BindView(R.id.system_tb)
    ToggleButton systemTb;

    @Override
    protected Context getActivityContext() {
        return this;
    }

    @Override
    protected int loadParentLayout() {
        return R.layout.activity_notification;
    }

    @Override
    protected void initViews() {
        SharedPreferences sp = SharedPreferenceUtil.getSp();
        boolean isCommment = sp.getBoolean(Constant.SPKey.NOTIFICATION_COMMENT, true);
        boolean isReply = sp.getBoolean(Constant.SPKey.NOTIFICATION_REPLY, true);
        boolean isFollow = sp.getBoolean(Constant.SPKey.NOTIFICATION_FOLLOW, true);
        boolean isLike = sp.getBoolean(Constant.SPKey.NOTIFICATION_LIKE, true);
        boolean isSystem = sp.getBoolean(Constant.SPKey.NOTIFICATION_SYSTEM, true);

        commentTb.setChecked(isCommment);
        feedCommentTb.setChecked(isReply);
        followTb.setChecked(isFollow);
        likeTb.setChecked(isLike);
        systemTb.setChecked(isSystem);
    }

    @Override
    protected void initListeners() {
        commentTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferences.Editor editor = SharedPreferenceUtil.getEditor();
                editor.putBoolean(Constant.SPKey.NOTIFICATION_COMMENT, isChecked);
                editor.apply();
            }
        });

        feedCommentTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferences.Editor editor = SharedPreferenceUtil.getEditor();
                editor.putBoolean(Constant.SPKey.NOTIFICATION_REPLY, isChecked);
                editor.apply();
            }
        });

        followTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferences.Editor editor = SharedPreferenceUtil.getEditor();
                editor.putBoolean(Constant.SPKey.NOTIFICATION_FOLLOW, isChecked);
                editor.apply();
            }
        });

        likeTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferences.Editor editor = SharedPreferenceUtil.getEditor();
                editor.putBoolean(Constant.SPKey.NOTIFICATION_LIKE, isChecked);
                editor.apply();
            }
        });

        systemTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SharedPreferences.Editor editor = SharedPreferenceUtil.getEditor();
                editor.putBoolean(Constant.SPKey.NOTIFICATION_SYSTEM, isChecked);
                editor.apply();
            }
        });
    }

    @Override
    protected void initLogic() {

    }

    @Override
    public void onClick(View v) {

    }
}
